package com.xwolf.camel.jms.polling;

import lombok.extern.log4j.Log4j2;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Exchange;
import org.apache.camel.Handler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ming
 * @Description:
 * @create 2019-01-05 2:02 PM
 **/

@Service("consumer")
@Log4j2
public class Consumer {

    @Autowired
    protected ConsumerTemplate consumer;

    @Handler
    public String consume() {
        StringBuilder result = new StringBuilder();
        log.info("triggered");
        Exchange exchange;
        while ((exchange = consumer.receive("activemq:queue:waiting", 1000)) != null) {
            result.append(exchange.getIn().getBody(String.class));
            log.info("I am here");
        }

        return result.toString();

    }
}
